/*
* Copyright (c) 2008-2011, Thomas Handorf
* 
* This file is part of libScopes.
* libScopes is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* 
* libScopes is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU Lesser General Public License
* along with libScopes.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifdef SCOPES_USEBOOSTSERIALIZATION
#include <boost/archive/text_oarchive.hpp> 
#include <boost/archive/text_iarchive.hpp> 
#endif // SCOPES_USEBOOSTSERIALIZATION
#include "array.h"
#include <iostream> 
#include <sstream> 

int main(){
   array<int>* vp0=new array<int>(4,(int[]){1,2,3,4});
   array<int>* vp1=new array<int>(*vp0); // copy constructor;
   if (!(vp0->isEq(*vp1))) {
      printf("copy constructor failed; arrays not the same\n");
      abort();
   }
   vp0->put(2,6);
   if ((vp0->isEq(*vp1))) {
      printf("copy constructor failed; arrays are still linked\n");
      abort();
   }
   array<int> v0=array<int>(4,(int[]){1,2,3,4});
   array<int> v1=v0; // copy constructor;
   if (!(v0.isEq(v1))) {
      printf("copy constructor failed; arrays not the same\n");
      abort();
   }
   v0.put(2,6);
   if ((v0.isEq(v1))) {
      printf("copy constructor failed; arrays are still linked\n");
      abort();
   }
   array<int>* ar0=new array<int>(6,7);
   array<char>* ar1=new array<char>;
   array<long>* ar2=new array<long>;
   ar0->print();
   ar1->print();
   ar2->print();
   ar1->put(0,1,5); // 5 x '1'
   ar1->print();
   ar2->put(3,2,5); // from index 3 on 5 x '2'
   ar2->print();
   ar2->add(*ar1,-1);
   ar2->print();
   ar2->replace(3,3,5,19); //array is extended accordingly
   ar2->print();
   (*ar2)[17]=3;
   // (*ar2)[111122]=3; // this may cause a segfault as length is not checked
   ar2->print();
   ar2->put(100005,100019); //array is extended accordingly
   printf("%ld %ld\n",ar2->at(100005),ar2->size());
   printf("%d %d %d \n",sizeof(long),sizeof(int),sizeof(char));
   // int8 subs[]={1,2,3,4};
   array<char>* ar3=new array<char>(4,(char[]){1,2,3,4});
   ar3->print();
   array<double>* ar4=new array<double>(4,(double[]){1.1,2.1,3.4,4.7});
   ar4->print();
   array<array<int>*>* arar1=new array<array<int>*>;
   arar1->push_back(new array<int>(4,(int[]){1,2,3,4}));
   arar1->push_back(new array<int>(3,(int[]){2,5,1}));
   arar1->print();
/*   string* str=new string();
   arar1->serialize(*str);
   array<array<int>*>* arar2=new array<array<int>*>;
   arar2->deserialize(*str,0);
   arar2->print();*/
   array<char>* b1=new array<char>(5,(char[]){1,2,0,0,2});
   array<char>* b2=new array<char>(5,(char[]){1,0,1,0,1});
   array<char>* b3=new array<char>(5,(char[]){0,0,1,5,1});
   printf("b1:");b1->print();
   printf("b2:");b2->print();
   printf("b1 AND b2:");b1->AND(*b2);b1->print();
   printf("(b1 AND b2) OR b2:");b1->OR(*b2);b1->print();
   printf("((b1 AND b2) OR b2) \\ b3:");b1->subSet(*b3);b1->print();
   array<char>* b4=new array<char>(10000000);
   array<char>* b5=new array<char>(10000000);
   printf("b4: %i, b5: %i\n",b4->nz(),b5->nz());
   size_t i;
   for (i=0;i<10000000;i++){
      (*b4)[i]=(char) (i+11);
   }
   for (i=0;i<10000000;i++){
      (*b5)[i]=(char) (i+7);
   }
   array<char>* b6=b4->copy();
   b6->AND(*b5);
   printf("b4: %i, b5: %i, b6: %i\n",10000000-b4->nz(),10000000-b5->nz(),10000000-b6->nz());
   
   return 0;
}   